class OrderItem < ActiveRecord::Base
  belongs_to :order
  belongs_to :article # so we can find out for example how many times a product has been ordered.
  
  validates_presence_of :article_id, :order_id, :quantity, :total_price
  
  def self.from_cart_item(cart_item)
    oi = self.new
    oi.article = cart_item.article
    oi.quantity = cart_item.quantity
    oi.total_price = cart_item.price
    oi
  end
end


# == Schema Information
#
# Table name: order_items
#
#  id          :integer         not null, primary key
#  article_id  :integer         not null
#  order_id    :integer         not null
#  quantity    :integer         not null
#  total_price :decimal(8, 2)   not null
#  created_at  :datetime
#  updated_at  :datetime
#

